package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    NursingLevelMapper nursingLevelMapper;
    @Override
    public PageResponse<NursingLevelVo> selectByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevel> nursingLevel = nursingLevelMapper.selectByPage(name, status);
        return PageResponse.of(nursingLevel,NursingLevelVo.class);
    }

    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insert(nursingLevel);

    }

    @Override
    public void delete(Long id) {
        nursingLevelMapper.delete(id);
    }

    @Override
    public NursingLevelVo getById(Long id) {
       NursingLevel nursingLevel = nursingLevelMapper.getById(id);
       return BeanUtil.toBean(nursingLevel,NursingLevelVo.class);
    }

    @Override
    public void upDateNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.upDateNursingLevel(nursingLevel);
    }

    @Override
    public void updateStatus(Long id, Integer status) {

        nursingLevelMapper.updateStatus(id,status);
    }

    @Override
    public List<NursingLevelVo> getAll() {

        return nursingLevelMapper.getAll();
    }
}
